package edu.fanhuiling.blogsystem.service;

import edu.fanhuiling.blogsystem.mapper.BlogInfoMapper;
import edu.fanhuiling.blogsystem.mapper.UserInfoMapper;
import edu.fanhuiling.blogsystem.model.BlogInfo;
import edu.fanhuiling.blogsystem.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;
    public UserInfo queryByName(String userName) {
      return  userInfoMapper.queryByName(userName);
    }

    public UserInfo queryById(Integer userId) {
        return userInfoMapper.queryById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        /*
         * 1、根据博客id，获取userId
         * 2、根据userId,获取userInfo
         *
         *
         * 通过博客表里面的id,找到对应的用户表的id,然后通过用户表的id，获取到作者信息
         * */
        BlogInfo blogInfo=blogInfoMapper.getDetailById(blogId);
        if (blogInfo==null||blogInfo.getUserId()<0){
            return null;//博客用户不存在
        }
        return userInfoMapper.queryById(blogInfo.getUserId());
    }
}
